from selenium import webdriver
from time import sleep
from selenium.webdriver.common.by import By

while True:
    wd = webdriver.Chrome(r'C:\Program Files\Google\Chrome\Application\chromedriver.exe')

    def isElementExist(element):  # 使用Xpath方式定位元素
        flag = True
        try:
            wd.find_element(By.XPATH, element)
            return flag
        except:
            flag = False
            return flag


    # wd.get('http://******************/web/')
    wd.get('http://172.16.0.6:8000/web/')
    wd.implicitly_wait(10)
    mainWindow = wd.current_window_handle
    wd.find_element(By.XPATH, '//*[@id="userName"]').send_keys('pcadmin')  # 账户
    wd.find_element(By.XPATH, '//*[@id="password"]').send_keys('111111')  # 密码
    wd.find_element(By.XPATH, '//*[@id="root"]/div/div[2]/div[2]/div/form/div[2]/div/div/div/button').click()  # 点击登录
    sleep(1)
    flag = isElementExist('/html/body/div[3]/div/div[2]/div/div[2]/div/div/div[2]/button[2]')  # 使用Xpath方式定位元素

    if flag:
        wd.find_element(By.XPATH, '/html/body/div[3]/div/div[2]/div/div[2]/div/div/div[2]/button[2]').click()  # 登陆提示 点击 继续
    sleep(5)
    wd.close()

